/**
 * 阅读计划相关API类型定义
 */

import type { BookSetRespVO, PictureBookRespVO } from './book'
import type {
  PageParams,
  PlanStatus,
  TimestampInfo,
} from './common'

// 阅读计划响应
export interface ReadingPlanRespVO extends TimestampInfo {
  id: number
  planName: string
  planType: string // collection-绘本集计划, custom-自定义计划
  cover?: string
  dailyCount: number // 每日阅读数量
  totalBooks: number
  estimatedDays: number
  currentDay: number
  completedBooks: number
  status: PlanStatus
  startDate: string // LocalDate格式: "2025-01-01"
  endDate?: string // LocalDate格式: "2025-01-01"
  nextTaskDate?: string // LocalDate格式: "2025-01-01"
  // 关联数据
  bookSets?: BookSetRespVO[]
  todayTasks?: PlanDailyTaskRespVO[]
}

// 阅读计划详情响应
export interface ReadingPlanDetailRespVO extends ReadingPlanRespVO {
  // 详情页面可能包含的额外字段
  bookSets?: BookSetRespVO[]
  dailyTasks?: PlanDailyTaskRespVO[]
  bookListByDay?: Record<number, PlanBookRespVO[]>
  statistics?: PlanStatistics
}

// 计划每日任务响应
export interface PlanDailyTaskRespVO {
  id: number
  planId: number
  bookId: number
  bookTitle: string
  bookCover: string
  taskDate: string // LocalDate格式: "2025-01-01"
  taskType: string // new_learning-新学习, review-复习
  status: string // pending-待完成, completed-已完成
  isReview: boolean
  readingTime?: number // 阅读时长（秒）
  completedTime?: string // 完成时间
  notes?: string // 备注
}

// 计划绘本响应
export interface PlanBookRespVO {
  id: number
  planId: number
  bookId: number
  bookSetId: number
  day: number
  sort: number
  isRequired: boolean
  estimatedMinutes: number
  // 绘本信息
  book: PictureBookRespVO
  // 阅读状态
  isCompleted: boolean
  readingProgress: number
  readingTime: number
  completedAt?: string
}

// 计划统计信息
export interface PlanStatistics {
  totalDays: number
  completedDays: number
  skippedDays: number
  totalBooks: number
  completedBooks: number
  totalTargetMinutes: number
  totalActualMinutes: number
  averageCompletionRate: number
  bestStreakDays: number
  currentStreakDays: number
  // 每日统计
  dailyStats: Array<{
    day: number
    date: string
    targetBooks: number
    completedBooks: number
    targetMinutes: number
    actualMinutes: number
    completionRate: number
  }>
  // 周统计
  weeklyStats: Array<{
    week: number
    startDate: string
    endDate: string
    completedDays: number
    totalBooks: number
    totalMinutes: number
  }>
}

// 创建阅读计划请求（与后端API匹配）
export interface ReadingPlanCreateReqVO {
  planName: string
  planType: string
  cover?: string
  dailyCount: number
  reviewSchedule: string[]
  collectionIds: number[]
}

// 更新阅读计划请求
export interface ReadingPlanUpdateReqVO {
  title?: string
  description?: string
  targetBooksPerDay?: number
  targetMinutesPerDay?: number
  isPublic?: boolean
  tags?: string[]
  reminderTime?: string
  weekendMode?: string
}

// 计划状态更新请求
export interface PlanStatusUpdateReqVO {
  status: PlanStatus
  reason?: string
}

// 完成任务请求
export interface CompleteTaskReqVO {
  taskId: number
  bookId: number
  readingTime: number
  notes?: string
}

// 跳过任务请求
export interface SkipTaskReqVO {
  taskId: number
  reason?: string
}

// 计划搜索参数
export interface PlanSearchParams extends PageParams {
  type?: string
  status?: PlanStatus
  difficulty?: string
  language?: string
  isPublic?: boolean
  userId?: number
  keyword?: string
}

// 推荐计划参数
export interface RecommendedPlansParams extends PageParams {
  difficulty?: string
  language?: string
  type?: string
  targetDays?: number
}

// 计划模板响应
export interface PlanTemplateRespVO {
  id: number
  name: string
  description: string
  type: string
  difficulty: string
  language: string
  totalDays: number
  targetBooksPerDay: number
  targetMinutesPerDay: number
  bookSetIds: number[]
  tags: string[]
  useCount: number
  rating: number
  isRecommended: boolean
}

// 计划分享信息
export interface PlanShareInfo {
  planId: number
  shareCode: string
  shareUrl: string
  qrCodeUrl: string
  expiresAt: string
}

// 计划评价
export interface PlanReview {
  id: number
  userId: number
  userNickname: string
  userAvatar?: string
  planId: number
  rating: number
  content: string
  images?: string[]
  likeCount: number
  isLiked?: boolean
  createTime: string
}

// 计划学习报告
export interface PlanLearningReport {
  planId: number
  reportDate: string
  totalDays: number
  completedDays: number
  totalBooks: number
  completedBooks: number
  totalMinutes: number
  averageMinutesPerDay: number
  completionRate: number
  streakDays: number
  improvements: string[]
  recommendations: string[]
  nextGoals: string[]
  // 图表数据
  dailyProgress: Array<{
    date: string
    books: number
    minutes: number
    completed: boolean
  }>
  categoryProgress: Array<{
    categoryName: string
    totalBooks: number
    completedBooks: number
    percentage: number
  }>
  difficultyProgress: Array<{
    difficulty: string
    totalBooks: number
    completedBooks: number
    averageTime: number
  }>
}

// 计划提醒设置
export interface PlanReminderSettings {
  planId: number
  enableReminder: boolean
  reminderTime: string // HH:mm格式
  reminderDays: number[] // 0-6，0表示周日
  reminderMessage?: string
  enablePushNotification: boolean
  enableEmailNotification: boolean
}

// 计划复制请求
export interface PlanCopyReqVO {
  sourcePlanId: number
  title: string
  startDate: string
  modifications?: {
    targetBooksPerDay?: number
    targetMinutesPerDay?: number
    totalDays?: number
    bookSetIds?: number[]
  }
}
